using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
namespace Fcdbas.Core
{
	[System.Serializable]
	public class SalFunctionalClass
	{
		
		public object _derived;
		[System.Diagnostics.DebuggerStepThrough]
		public static implicit operator bool(SalFunctionalClass hUdv)
		{
			return hUdv != null;
		}
		public string GetTypeName()
		{
			return base.GetType().Name;
		}
		public static SalFunctionalClass CreateFromString(string className)
		{
			return SalFunctionalClass.CreateFromString(className, System.Reflection.Assembly.GetCallingAssembly());
		}
		internal static SalFunctionalClass CreateFromString(string className, System.Reflection.Assembly asm)
		{
			System.Type type = ResolveType(asm, className);
			if (type == null)
			{
				return null;
			}
			return (SalFunctionalClass)System.Activator.CreateInstance(type);
		}
		public bool IsDerivedFrom(string className)
		{
			return this.IsDerivedFrom(className, System.Reflection.Assembly.GetCallingAssembly());
		}
		public bool IsDerivedFrom(System.Type type)
		{
			return TypeManager.IsDerivedFrom(base.GetType(), type);
		}
        public static System.Type ResolveType(System.Reflection.Assembly asm, string typeName)
        {
            System.Type result;
            try
            {
                System.Type type = null;
                if (typeName.IndexOf('.') > -1)
                {
                    if (asm != null)
                    {
                        type = asm.GetType(typeName);
                    }
                    if (type == null)
                    {
                        type = System.Type.GetType(typeName);
                    }
                }
                if (type == null)
                {
                    type = TypeManager.LookupType(typeName, true);
                }
                result = type;
            }
            catch (System.TypeLoadException e)
            {
                Sys.TraceException(Sys.TraceSystem, e, TraceLevel.Error);
                result = null;
            }
            return result;
        }
		internal bool IsDerivedFrom(string className, System.Reflection.Assembly asm)
		{
			System.Type type = ResolveType(asm, className);
			return !(type == null) && this.IsDerivedFrom(type);
		}
		public static bool IsValidClassName(string className)
		{
			return SalFunctionalClass.IsValidClassName(className, System.Reflection.Assembly.GetCallingAssembly());
		}
		internal static bool IsValidClassName(string className, System.Reflection.Assembly asm)
		{
			System.Type left = ResolveType(asm, className);
			return left != null;
		}
	}
}
